package com.zy.chat.controller;


import com.zy.chat.dto.UserDTO;
import com.zy.chat.entity.UserInfo;
import com.zy.chat.service.UserService;
import com.zy.chat.vo.RequestParams;
import com.zy.chat.vo.UserResult;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = {"/usercontroller"})
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/user/{userId}")
    public ResponseEntity<List<UserInfo>> getFriendList(@PathVariable(value = "userId")String userId) throws Exception{
        List<UserInfo> friendlist=this.userService.getFriendList(userId);
        return new ResponseEntity<List<UserInfo>>(friendlist, HttpStatus.OK);
    }


    @PostMapping("/list")
    public ResponseEntity<UserResult> search(@RequestBody RequestParams params) {
        return new ResponseEntity<UserResult>( userService.search(params),HttpStatus.OK);
    }

    @GetMapping("/suggestion/{key}")
    public ResponseEntity<List<String>> getSuggestion(@PathVariable(value = "key") String key) throws  Exception{
        return new ResponseEntity<List<String>>(userService.getSuggestion(key),HttpStatus.OK);
    }

    @PostMapping("/getremmend")
    public ResponseEntity<List<UserInfo>> getRemmend(@RequestBody UserInfo userInfo){
        return new ResponseEntity<List<UserInfo>>(this.userService.recommended(userInfo),HttpStatus.OK);
    }

    @GetMapping(value = "/person/{username}")
    public ResponseEntity<UserDTO> query(@PathVariable(value = "username")String username){
        return new ResponseEntity<UserDTO>(userService.person(username),HttpStatus.OK);
    }

    @GetMapping(value = "/sign")
    public  ResponseEntity<Boolean> sign(){
        System.out.println(11);
        return new ResponseEntity<Boolean>(userService.sign(),HttpStatus.OK);
    }

    @GetMapping("/sign/count")
    public ResponseEntity<Integer> count(){
        return new ResponseEntity<Integer>(userService.signcount(),HttpStatus.OK);
    }


}
